@extends('Home/Layout/baseusercenter')

@section('title', '个人信息')

{{--  首页主体  --}}
@section('main')

@section('title2', '个人信息')
            <div class="uc-content">
                <div class="uc-panel">
                    <div class="uc-bigtit">个人信息</div>
                    <div class="uc-panel-bd">
                        <div class="account-info clearfix">
                            <div class="col-userinfo">
                                <div class="control-group">
                                    <div class="hd">昵称：</div>
                                    @php
                                        $nickname = $userinfo['nickname'];
                                    @endphp
                                    <div class="bd"><input id='nickname' class="ui-txtin" type="text" name="nickname" value="{{isset($nickname)?$nickname : '新用户'}}" /></div>
                                </div>

                                <div class="control-group">
                                     @php
                                        $sex = $userinfo['sex'];
                                    @endphp
                                    <div class="hd">性别：</div>
                                    <div id='sex' class="bd">
                                        <label class="check">
                                            @if($sex == 1)
                                            <input checked type="radio" name="sex" value="1" />男
                                            @else
                                            <input type="radio" name="sex" value="1" />男
                                            @endif
                                        </label>
                                        <label class="check ml25">
                                            @if($sex == 2)
                                            <input checked type="radio" name="sex" value="2" />女
                                            @else
                                            <input  type="radio" name="sex" value="2" />女
                                            @endif
                                        </label>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="hd">电话：</div>
                                    @php
                                        $phone = $userinfo['phone'];
                                    @endphp
                                    <div class="bd">
                                        <input id='phone' class="ui-txtin" type="text" name="phone"  value="{{$phone}}" />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <div class="hd">详细地址：</div>
                                     @php
                                        $address = $userinfo['address'];
                                    @endphp
                                    <div class="bd">
                                        <input id='address' class="ui-txtin" type="text" name="address"  value="{{$address}}" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="hd">邮箱：</div>
                                     @php
                                        $email = $userinfo['email'];
                                    @endphp
                                    <div class="bd">
                                        <input id='email' class="ui-txtin" type="text" name="email"  value="{{$email}}" />
                                    </div>
                                </div>
                                <div class="control-submit">
                                    <input id='action' class="ui-btn-theme submit" type="button" value="保存" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--脚部-->
    <div class="fatfooter">

    </div>
    <!--脚部-->
</body>
@endsection

@section('footer-js')
    <script>
        $('#action').on('click', function () {
            var unickname = $('input[name="nickname"]').val();
            var uemail = $('input[name="email"]').val();
            var uaddress = $('input[name="address"]').val();
            var usex = $('input[name="sex"]').val();
            var uphone = $('input[name="phone"]').val();

        $.axpost(
            'post',
            '{{url("/editUc")}}',
            'nickname='+unickname+'&email='+uemail+'&_token={{csrf_token()}}'+'&address='+uaddress+'&phone='+uphone+'&sex='+usex,

            function (data) {
                
                if (data.status==1200) {

                    layer.alert(data.msg, {icon:1});
                    
                }

                if (data.status==1400) {

                    layer.alert(data.msg, {icon:2});
                    
                }
            },

           function (tipString) {

                if (tipString.responseText) {
                    var tipObj = JSON.parse(tipString.responseText).errors;
                    //console.log(tipObj);
                   
                   if (tipObj['nickname']) {

                        layer.tips(tipObj['nickname'], '#nickname', {
                            tips:[2, '#FF0000'],
                            tipsMore: true

                        });
                   }

                   if (tipObj['sex']) {
                        layer.tips(tipObj['sex'], '#sex', {
                            tips:[4, '#FF0000'],
                            tipsMore: true
                        });
                    }

                    if (tipObj['email']) {
                        layer.tips(tipObj['email'], '#email', {
                            tips:[2, '#FF0000'],
                            tipsMore: true
                        });
                    }

                    if (tipObj['address']) {
                        layer.tips(tipObj['address'], '#address', {
                            tips:[2, '#FF0000'],
                            tipsMore: true
                        });
                    }

                    if (tipObj['phone']) {
                        layer.tips(tipObj['phone'], '#phone', {
                            tips:[2, '#FF0000'],
                            tipsMore: true
                        });
                    }
                }
            }
        );
    });
    </script>

@endsection

